package cc.yugu.yhdw.webserver.service.basic;

import cc.yugu.yhdw.common.domain.basic.CustomerDepositGift;
import cc.yugu.yhdw.webserver.persistence.basic.CustomerDepositGiftMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
 * 顾客充值优惠业务
 * 
 * @Date:Created in 2018/7/3 14:13
 * @Author:
 * @Modified By: zjn 2018/7/3 14:13
 */ 
@Service
public class CustomerDepositGiftService {
    @Autowired
    CustomerDepositGiftMapper customerDepositGiftMapper;
    /**
    * 查询表bas_customer_deposit_gift中信息,并按照金额升序排列返回
    * 
    * @Param: []
    * @Return: java.util.List<cc.yugu.yhdw.common.domain.basic.CustomerDepositGift>
    * @Author By: zjn 2018/7/3  14:14
    */ 
    public List<CustomerDepositGift> findAll() {
        return customerDepositGiftMapper.findAll();
    }
    /**
    * 更新表
    * 
    * @Param: [money, gift]
    * @Return: void
    * @Author By: zjn 2018/7/3  14:15
    */ 
    @Transactional
    public void update(double[] money, float[] gift) {
        // 删除表
        customerDepositGiftMapper.clear();

        for(int i = 0; i < money.length; i++) {
            if(money[i] != 0) {
                CustomerDepositGift line = new CustomerDepositGift();
                line.setMoney((int)(money[i]*100));
                line.setGift(gift[i]);

                customerDepositGiftMapper.insert(line);
            }
        }
    }
}
